<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Created by CodeTlan.
 * User: Ing. Miguel Salas
 * Date: 3/29/12
 * Time: 12:27 AM
 */
class Historiales extends CT_Controller
{
    function __construct(){
        parent::__construct();
        $this->load->model("historial", "dao");
    }

    function add(){
        $data["titulo"]=$this->input->post("titulo");
        $data["fecha"]=$this->input->post("fecha");
        $data["descripcion"]=$this->input->post("descripcion");
        $data["activo"]=1;
        $data["estatus"]=1;
        echo $this->_add($data);
    }

    function edit(){
        $data=(array) json_decode($this->input->post("mod"));
        echo $this->_edit($data,array('historial_k' => $this->input->post('historial_k')));
    }

    function active()
    {
        echo $this->_edit(array('activo' => $this->input->post('activo')), array('historial_k' => $this->input->post('historial_k')));
    }

    function delete()
    {
        echo $this->_edit(array("estatus" => 0), array('historial_k' => $this->input->post('historial_k')));
    }

    function find(){
        $result=$this->dao->find('historial_k, titulo, fecha, descripcion, activo','',$this->input->post("start"),NUM_ROWS);
        echo $this->getSuccess($result);
    }

    function findfotos(){
        $result=$this->dao->findFotos('foto_k, historial_k, foto',array('historial_k' => $this->input->post('historial_k')),$this->input->post("start"),NUM_ROWS);
        echo $this->getSuccess($result);
    }

    function addfoto(){
        $upload=$this->uploadfile();

        if($upload["success"]===false){
            echo json_encode($upload);
            return;
        }

        $data["historial_k"]=$this->input->post("historial_k");
        $data["foto"]= 'uploads/'.$upload["data"]["file_name"];
        $data["estatus"]=1;
        echo $this->_add($data,'CT_historiales_fotos');
    }

    function deletefoto()
    {
        echo $this->_edit(array("estatus" => 0), array('foto_k' => $this->input->post('foto_k')),'CT_historiales_fotos');
    }
}
